﻿using Microsoft.Practices.Unity;

namespace MvvmFx.Common.ViewModels.Behaviors.ProcessManagement
{
    /// <summary>
    /// Abstract base StateSaver class to save the properties of a ProfileStae
    /// object to the object being edited
    /// </summary>
    public abstract class StateSaver<T> : IStateSaver<T> where T : ProcessState
    {
        /// <summary>
        /// Create a StateSaver
        /// </summary>
        protected StateSaver(IUnityContainer container)
        {
            this.Container = container;
        }

        #region properties

        /// <summary>
        /// Dependency container to be used for DI by child classes.
        /// </summary>
        protected IUnityContainer Container
        {
            get;
            private set;
        }

        #endregion

        /// <summary>
        /// Save the profile page object, using the data in the manager's State
        /// </summary>
        /// <returns></returns>
        public void Save(T state)
        {
            OnSave(state);

            // Mark the state as being UnModified
            //
            state.IsModified = false;
        }

        protected abstract void OnSave(T state);

        #region IStateSaver Members

        void IStateSaver.Save(ProcessState state)
        {
            Save((T)state);
        }

        #endregion
    }
}